package main

import (
        "math/rand"
        "runtime"
        "time"

        "github.com/bytedance/Elkeid/plugins/collector/engine"
        plugins "github.com/bytedance/plugins"
        "github.com/bytedance/plugins/log"
        "github.com/go-logr/zapr"
        "go.uber.org/zap"
        "go.uber.org/zap/zapcore"
)

func init() {
        runtime.GOMAXPROCS(8)
        rand.Seed(time.Now().UnixNano())
}

func main() {
        c := plugins.New()
        l := log.New(
                log.Config{
                        MaxSize:     1,
                        Path:        "collector.log",
                        FileLevel:   zapcore.InfoLevel,
                        RemoteLevel: zapcore.ErrorLevel,
                        MaxBackups:  10,
                        Compress:    true,
                        Client:      c,
                },
        )
        defer l.Sync()
        zap.ReplaceGlobals(l)
        e := engine.New(c, zapr.NewLogger(l))

        // 手动打印输出
        zap.L().Info("手动运行打印输出：程序启动")

        // 创建 engine.Cache 实例
        cache := engine.NewCache()

        // 手动调用处理器
        zap.L().Info("开始手动调用处理器...")

        processHandler := &ProcessHandler{}
        portHandler := &PortHandler{}
        //userHandler := &UserHandler{}
        //cronHandler := &CronHandler{}
        //serviceHandler := &ServiceHandler{}
        //softwareHandler := &SoftwareHandler{}
        //containerHandler := &ContainerHandler{}
        //integrityHandler := &IntegrityHandler{}
        //netInterfaceHandler := &NetInterfaceHandler{}
        //volumeHandler := &VolumeHandler{}
        //kmodHandler := &KmodHandler{}
        //appHandler := &AppHandler{}

        // 调用处理器的 Handle 方法，传递正确的参数
        processHandler.Handle(c, cache, "ProcessHandler")
        portHandler.Handle(c, cache, "PortHandler")
        //userHandler.Handle(c, cache, "UserHandler")
        //cronHandler.Handle(c, cache, "CronHandler")
        //serviceHandler.Handle(c, cache, "ServiceHandler")
        //softwareHandler.Handle(c, cache, "SoftwareHandler")
        //containerHandler.Handle(c, cache, "ContainerHandler")
        //integrityHandler.Handle(c, cache, "IntegrityHandler")
        //netInterfaceHandler.Handle(c, cache, "NetInterfaceHandler")
        //volumeHandler.Handle(c, cache, "VolumeHandler")
        //kmodHandler.Handle(c, cache, "KmodHandler")
        //appHandler.Handle(c, cache, "AppHandler")

        zap.L().Info("处理器调用完成")

        e.Run()
}

